package infiews.scheduler;

import infiews.crawler.Config;
import infiews.crawler.Crawler;
import infiews.crawler.exceptions.CrawlerException;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by IntelliJ IDEA.
 * User:
 * Date: 25.4.11
 * Time: 0.57
 * To change this template use File | Settings | File Templates.
 */
public class Scheduler {
	public static void main(String args[]) throws Exception{
		Config conf = new Config();
		Timer timer = new Timer();
		Calendar date = Calendar.getInstance();
		date.set(Calendar.HOUR, conf.getInt("schedule.hour"));
		date.set(Calendar.MINUTE, conf.getInt("schedule.minutes"));
		date.set(Calendar.SECOND, conf.getInt("schedule.seconds"));
		date.set(Calendar.MILLISECOND, 0);
		timer.schedule(new Runner(), date.getTime(), 1000 * 60 * 60 * 24);
	}
}

class Runner extends TimerTask {
	public void run(){
		try{
			Crawler crawler = new Crawler();
			crawler.start();
		}catch(CrawlerException e){
			e.printStackTrace();
		}
	}
	
}